package com.mistyrain.service.impl;

import com.mistyrain.entity.User;
import com.mistyrain.entity.UserVO;
import com.mistyrain.mapper.UserMapper;
import com.mistyrain.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;
    @Override
    public UserVO findAll(int page, int limit) {
        UserVO userVO = new UserVO();
        userVO.setCode(0);
        userVO.setMsg("");
        userVO.setCount(userMapper.count());
        userVO.setData(userMapper.findAll((page-1)*limit,limit));
        return userVO;
    }

    @Override
    public int count() {
        return userMapper.count();
    }

    @Override
    public void save(User user) {
        user.setRegisterdate(new Date());
        userMapper.save(user);
    }

    @Override
    public void deleteById(long id) {
        userMapper.deleteById(id);
    }
}
